package com.killer.system.controller;


import com.killer.common.entity.Result;
import com.killer.common.util.JwtUtil;
import com.killer.system.entity.Admin;
import com.killer.system.service.IAdminService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.killer.db.controller.BaseController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 后台用户表 前端控制器
 * </p>
 *
 * @author killer
 * @since 2021-08-18
 */
@RestController
@RequestMapping("/admin")
public class AdminController extends BaseController<IAdminService, Admin> {

    @PostMapping("/login")
    public Result login(@RequestBody Admin admin) {
        boolean result = baseService.login(admin);
        if (result) {
            //生成token
            String token = JwtUtil.createJWT(admin.getId(), admin.getLoginName());
            Map<String, Object> info = new HashMap<>();
            info.put("token", token);
            return Result.success(info);
        } else {
            return Result.fail("用户名或密码错误");
        }
    }

}
